﻿
//pre loads the 3 images for the profile so that the
//mouseover event should be as smooth as possible
//using preload jQuery plugin 
function preLoadImgs() {


    $.preload('../images/myprofilepic.jpg',
                '../images/famImg.jpg',
                '../images/signImg.jpg',
                '../images/programmer_cartoon.jpg',
                '../images/info.png',
                '../images/error.png',
                '../images/fancybox_sprite.png');



}



function hideUseNameImgs(){

    $("#errorImg").hide();
    $("#goodImg").hide();
    userNMmsg
}

function showUserNameOk(msg){

    $("#errorImg").hide();
    $("#goodImg").show();
    $("#userNMmsg").text(msg);
}


function showUserNotOk(msg){

    $("#goodImg").hide();
    $("#errorImg").show();
    $("#userNMmsg").text(msg);
}


$(document).ready(function () {

    hideUseNameImgs();
   
    $("#username").bind('blur', function () {


        var userName = $("#username").val();


        var request = $.ajax({
            type: 'POST',
            url: "/register",
            dataType: "json",
            data: { username: userName, precheck: true }


        });
        request.done(function (data) {

            if (data.nameOk) {
                showUserNameOk(data.msg);
            }
            else {

                showUserNotOk(data.msg);

            }



        });



    });

});


